/*  iImager (network disk imaging via iscsi)
	Copyright (C) 2009-2010 Yao Wei <njustyw@gmail.com>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#ifndef Q_ISCSI_FINDER_H
#define Q_ISCSI_FINDER_H

#include <QtNetwork>
#include "trimps_forensic_global.h"

/** The iSCSI iSCSIDiscovery, here we implement from connection to an iscsi daemon service */
class ISCSIFinder : public QObject
{
	Q_OBJECT
public:
	ISCSIFinder(QObject* parent = 0);
	~ISCSIFinder();

	/** Add one iSCSI rack ip */
	void addIP(const QString& ip);

	/** Remove one iSCSI rack ip */
	void removeIP(const QString& ip);

	/** Close connection to iscsi daemon service*/
	void closeDaemonConnection();

private slots:
	/** What will be done when some error occured by the service daemon */
	void serviceError(QAbstractSocket::SocketError);
	
	/** What will be done when the service daemon is connected*/
	void serviceConnected();
	
	/** What will be done when the service daemon is disconnected*/
	void serviceDisconnected();
	
	/** What will be done when we receive data from the service daemon*/
	void dataReceived();

	/** Start connecting to iscsi daemon service*/
	void connectToService();


signals:
	/** This signal is emitted when the service daemon is connected or disconnected*/
	void serviceStatus(bool flag);
	
	/** This signal is emitted when the rack machine is connected or disconnected*/
	void ipAddStatus(const QString& ip, bool flag);
	
	/** 
	 This signal is emitted when a new hard disk  comes out 
	 @param ip the rack ip address list
	 @param device the device name list
	 @param target the iscsi target name list
	*/
	void diskAdd(const QStringList &ipList, const QStringList& deviceList, const QStringList& targetList);
	
	/** 
	This signal is emitted when a hard disk is pulled out 
	 @param ip the rack ip address list
	 @param device the device name list
	 @param target the iscsi target name list
	*/
	void diskRemove(const QStringList &ipList, const QStringList& deviceList, const QStringList& targetList);

private:
	QTcpSocket *tcpSocket;
	QStringList ipList;

	QHash<QString,  QHash<QString, QString> > liveAllDisks;

	int socketConnectCount;

	bool aboutToExit;

	friend class ISCSIProxyThread;
};

#endif
